$(function(){
    // 通过
    $('.agree').on('click',function(){
        var id = $(this).attr('id');
        var status=$(this).attr('status');
        ajax('post','/withdraw/change-status',{id:id,status:status},function(data){
            layer.msg(data.msg);
            setTimeout(function(){
                location.reload();
            },1200);
        })
    });
    // 未通过
    $('.disagree').on('click',function(){
        var id = $(this).attr('id');
        var status=$(this).attr('status');
        AgreeBox();
        $(".b-confirm").on('click',function(){
            var reason=$('.b-text').val();
            if(reason!=''){
                ajax('post','/withdraw/change-status',{id:id,status:status,dismissal:reason},function(data){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        location.reload();
                    },1200);
                })
            }else{
                layer.msg('原因不能为空')
            }
        });
        $('.b-cancel').on('click',function(){
            $('.b-div').hide();
        })
    });
    
    function AgreeBox(){
        var dIv=$("<div class='b-div'><h4 class='b-h4'>提示</h4><p class='b-p'>请输入原因</p><textarea class='b-text'></textarea><div class='b-btn'><input type='button' value='确认' class='b-confirm btn-primary'><input type='button' value='取消' class='b-cancel'></div></div>");
        $("body").append(dIv);
    };
    
    
    $('.payMoney').on('click',function () {
        var id = $(this).attr('id');
        $.ajax({
            'type':'POST',
            'url':'/withdraw/pay-money',
            'data':{
                id:id
            },
            'dataType':'json',
            'beforeSend':function(){
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            },
            'success':function(data)
            {
                layer.closeAll();
                if(data.code != 200)
                {
                    layer.alert(data.msg);
                    return false;
                }
                location.href = '/withdraw/index';
            }

        });
        
    })
});